#include "ClassFive.h"
#include <iostream>

int main()
{
    AI a;
    Player p('x');
    Board *b;
    b = Board::GetBoard(10);
    Chess c;

    int row = 0, column = 0;
    char player = 'x';
    while (1)
    {
        b->PrintBoard();

        if (player == 'x')
        {
            printf("请|%c|下棋", player);

            // 阻塞形函数:让函数等待条件满足
            scanf("%d %d", &row, &column);
            if (p.Makemove(b, row - 1, column - 1, player) == false)
            {
                continue;
            }
            if (p.CheckIsWin(b, row - 1, column - 1, player) == true)
            {
                b->PrintBoard();
                printf("恭喜|%c|获胜", player);
                break;
            }
            if (p.CheckIsDraw(b, c) == true)
            {
                b->PrintBoard();
                printf("平局！\n");
                break;
            }
        }
        if (player == 'o')
        {
            printf("电脑正在下棋\n");
            if (a.AIMakeMove(b, 'x', 'o', row - 1, column - 1, p) == false)
            {
                continue;
            }
            if (p.CheckIsWin(b, row - 1, column - 1, 'o') == true)
            {
                b->PrintBoard();
                printf("恭喜|%c|获胜", player);
                break;
            }
            if (p.CheckIsDraw(b, c) == true)
            {
                b->PrintBoard();
                printf("平局！\n");
                break;
            }
        }
        if (player == 'x')
        {
            player = 'o';
        }
        else if (player == 'o')
        {
            player = 'x';
        }
    }

    return 0;
}
